//
//  CarcircleViewController.m
//  CarUser
//
//  Created by 王森林 on 2018/11/29.
//  Copyright © 2018年 王森林. All rights reserved.
//

#import "CarcircleViewController.h"
#import "WMPageController.h"
#import "CarcircleMainViewController.h"
#import "CarcircleAddViewController.h"
@interface CarcircleViewController ()
//@property (nonatomic, strong) WMPageController *mainVc;
@end

@implementation CarcircleViewController

- (void)viewDidLoad {
    
    
    self.titleSizeNormal = 14;
    self.titleSizeSelected = 14;
    self.titleColorNormal = [UIColor whiteColor];
    self.titleColorSelected =  [UIColor whiteColor];
    self.showOnNavigationBar = YES;
    self.progressHeight = 1.5f;
    self.progressWidth = BOUNDWIDTH/4-20;
    self.progressColor = self.titleColorSelected;
    self.menuViewStyle = WMMenuViewStyleLine;
    self.progressViewCornerRadius = 5;
    self.progressViewBottomSpace = 5;
//    self.preloadPolicy = WMPageControllerPreloadPolicyNeighbour;
    self.itemsWidths = @[@(BOUNDWIDTH/4),@(BOUNDWIDTH/4),@(BOUNDWIDTH/4)];
    
    [super viewDidLoad];
//    self.fd_prefersNavigationBarHidden = YES;
    
    if (!IS_IPHONE_X) {
            UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
            if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
                statusBar.backgroundColor = Common_NavigroundColor;
            }
    } else {
//        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
//        UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
//        statusBar.backgroundColor = Common_NavigroundColor;
        
        
    }
//    //页面
//    _mainVc = [[WMPageController alloc]init];
//    _mainVc.delegate = self;
//    _mainVc.dataSource = self;
//
//
//
//    _mainVc.titles = @[@"用车养车",@"购车交流",@"帮选车",@"车市行情"];
//    _mainVc.itemsWidths = @[@(BOUNDWIDTH/4),@(BOUNDWIDTH/4),@(BOUNDWIDTH/4)];
//    _mainVc.titleSizeNormal = 14;
//    _mainVc.titleSizeSelected = 14;
//    _mainVc.titleColorNormal = [UIColor whiteColor];
//    _mainVc.titleColorSelected =  [UIColor whiteColor];
//
//    _mainVc.progressHeight = 1.5f;
//    _mainVc.progressWidth = BOUNDWIDTH/4-20;
//    _mainVc.progressColor = _mainVc.titleColorSelected;
//    _mainVc.menuViewStyle = WMMenuViewStyleLine;
//    _mainVc.progressViewCornerRadius = 5;
//    _mainVc.progressViewBottomSpace = 5;
//
//
//    [self addChildViewController:_mainVc];
//    [self.view addSubview:_mainVc.view];
//    _mainVc.view.bounds = self.view.bounds;
//
//   _mainVc.menuView.backgroundColor = Common_NavigroundColor;
    
    
    UIButton *addBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    addBtn.frame = CGRectMake(BOUNDWIDTH - 80, BOUNDHEIGHT-TABBAR_HEIGHT-NAV_HEIGHT -100, 60, 60);
    [addBtn setImage:IMG(@"comment_add") forState:UIControlStateNormal];
    [addBtn addTarget:self action:@selector(handleAddAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:addBtn];
    
    
    // Do any additional setup after loading the view.
}

- (void)handleAddAction:(id)sender
{
    UserRes *user = [CommonMethod getUser];
    if (!user) {
        [[NSNotificationCenter defaultCenter]postNotificationName:NotificationCenterName_AlertLoginVC object:nil];
        return;
    }
    
    CarcircleAddViewController *controller  = [[CarcircleAddViewController alloc] init];
    controller.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:controller animated:YES];
    
}
#pragma mark - WMPageControllerDataSource
- (NSInteger)numbersOfChildControllersInPageController:(WMPageController *)pageController {
    return 4;
}

- (UIViewController *)pageController:(WMPageController *)pageController viewControllerAtIndex:(NSInteger)index {
    CarcircleMainViewController *controller = [[CarcircleMainViewController  alloc] init];
    controller.type = [NSString stringWithFormat:@"%ld",index];
    return controller;

}

- (NSString *)pageController:(WMPageController *)pageController titleAtIndex:(NSInteger)index {
    //@[@"用车养车",@"购车交流",@"帮选车",@"车市行情"];
    switch (index) {
        case 0:
            return @"用车养车";
            break;
        case 1:
            return @"购车交流";
            break;
        case 2:
            return @"帮选车";
            break;
        case 3:
            return @"车市行情";
            break;
            
        default:
            return @"";
            break;
    }
}

- (CGRect)pageController:(WMPageController *)pageController preferredFrameForContentView:(WMScrollView *)contentView{
    //    return _contentFrame;
    
    return CGRectMake(0, 0, BOUNDWIDTH, BOUNDHEIGHT);
}

- (CGRect)pageController:(WMPageController *)pageController preferredFrameForMenuView:(WMMenuView *)menuView{
    //    menuView.scrollView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
    //    return _menuFrame;
    
    return CGRectMake(0, 0, BOUNDWIDTH, 45);
}

- (void)pageController:(WMPageController *)pageController lazyLoadViewController:(__kindof UIViewController *)viewController withInfo:(NSDictionary *)info {
    //    NSLog(@"%@", info);
}

- (void)pageController:(WMPageController *)pageController willEnterViewController:(__kindof UIViewController *)viewController withInfo:(NSDictionary *)info {
    //    NSLog(@"%@", info);
}


- (void)pageController:(WMPageController *)pageController didEnterViewController:(__kindof UIViewController *)viewController withInfo:(NSDictionary *)info {
    //    NSLog(@"%s", __FUNCTION__);
}

- (void)menuView:(WMMenuView *)menu didLayoutItemFrame:(WMMenuItem *)menuItem atIndex:(NSInteger)index {
//        NSLog(@"%@", NSStringFromCGRect(menuItem.frame));
}


//#pragma mark - WMPageControllerDataSource
//- (NSInteger)numbersOfChildControllersInPageController:(WMPageController *)pageController {
//    return _mainVc.titles.count;
//}
//
//- (UIViewController *)pageController:(WMPageController *)pageController viewControllerAtIndex:(NSInteger)index {
//    CarcircleMainViewController *controller = [[CarcircleMainViewController  alloc] init];
//    controller.type = [NSString stringWithFormat:@"%ld",index];
//    return controller;
//}
//
//- (NSString *)pageController:(WMPageController *)pageController titleAtIndex:(NSInteger)index {
//    return _mainVc.titles[index];
//}
//
//- (CGRect)pageController:(WMPageController *)pageController preferredFrameForContentView:(WMScrollView *)contentView{
//    CGRect rect = self.view.bounds;
//    rect.origin.y = IS_IPHONE_X?94:70;
//    rect.size.height = rect.size.height - rect.origin.y;
//    return rect;
//}
//
//- (CGRect)pageController:(WMPageController *)pageController preferredFrameForMenuView:(WMMenuView *)menuView{
//    return CGRectMake(0, IS_IPHONE_X?44:20, BOUNDWIDTH, 50);
//}
//
//- (void)pageController:(WMPageController *)pageController lazyLoadViewController:(__kindof UIViewController *)viewController withInfo:(NSDictionary *)info {
//
//}
//
//- (void)pageController:(WMPageController *)pageController willEnterViewController:(__kindof UIViewController *)viewController withInfo:(NSDictionary *)info {
//
//}
//
//
//- (void)pageController:(WMPageController *)pageController didEnterViewController:(__kindof UIViewController *)viewController withInfo:(NSDictionary *)info {
//    //    @weakify(self);
//    //    [self.mainVc.titles enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
//    //        @strongify(self);
//    //        if (idx == self.mainVc.selectIndex) {
//    //
//    //        }else{
//    //
//    //        }
//    //    }];
//}
//
//- (void)menuView:(WMMenuView *)menu didLayoutItemFrame:(WMMenuItem *)menuItem atIndex:(NSInteger)index {
//
//}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
